<?php

namespace app\api\model;

use think\Db;
use think\Model;

/**
 * 会员模型
 * @method static mixed getByUsername($str) 通过用户名查询用户
 * @method static mixed getByNickname($str) 通过昵称查询用户
 * @method static mixed getByMobile($str) 通过手机查询用户
 * @method static mixed getByEmail($str) 通过邮箱查询用户
 */
class User extends Model
{

    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    // 追加属性
    protected $append = [
        //'level_text',
        'gender_text'
    ];


    public function getLevelLabelTextAttr($data)
    {
        $label = [];

        if ($data['auth_status']==2||$data['company_auth_status']==2){
            if (in_array($data['level_type'],[2,3,5])){
                array_push($label,'F');
            }

            if ($data['person_auth']==1||$data['auth_status']==2){
                array_push($label,'g');
            }

            if ($data['company_auth']==1||$data['company_auth_status']==2){
                array_push($label,'G');
            }

            if ($data['level_type']==3){
                array_push($label,'m');
            }
            $star_list = $this->getStarList();
            $label_txt = implode('',$label).$star_list[$data['level']];
        } else {
            if ($data['auth_status']!=2){
                if ($data['person_auth']!=1){
                    array_push($label,'P01');
                } elseif ($data['person_auth']==1){
                    array_push($label,'P02');
                }
                $label_txt = implode('',$label);

            } elseif ($data['company_auth_status']!=2){
                if ($data['company_auth']!=1){
                    array_push($label,'P01');
                } elseif ($data['company_auth']==1){
                    array_push($label,'P02');
                }
                $label_txt = implode('',$label);
            }
        }
        /*if ($data['auth_status']!=2){
            if ($data['person_auth']!=1){
                array_push($label,'P01');
            } elseif ($data['person_auth']==1){
                array_push($label,'P02');
            }
            $label_txt = implode('',$label);

        } elseif ($data['company_auth_status']!=2){
            if ($data['company_auth']!=1){
                array_push($label,'P01');
            } elseif ($data['company_auth']==1){
                array_push($label,'P02');
            }
            $label_txt = implode('',$label);
        } else {
            if (in_array($data['level_type'],[2,3,5])){
                array_push($label,'F');
            }

            if ($data['person_auth']==1){
                array_push($label,'g');
            }

            if ($data['company_auth']==1){
                array_push($label,'G');
            }
            if ($data['level_type']==3){
                array_push($label,'m');
            }
            $star_list = $this->getStarList();
            $label_txt = implode('',$label).$star_list[$data['level']];
        }*/

        return $label_txt;
    }

    public function getLevelList()
    {
        return [1=>'普享会员',2=>'惠享会员',3=>'乐享会员',4=>'优享会员',5=>'尊享会员'];
    }

    public function getStarList()
    {
        return [1=>'☆',2=>'☆☆',3=>'☆☆☆',4=>'☆☆☆☆',5=>'☆☆☆☆☆'];
    }

    public function getLeveTypelList()
    {
        return [1=>'个人非业主会员',2=>'个人业主会员',3=>'个人业主免费换房会员',4=>'单位非业主会员',5=>'单位业主会员'];
    }

    public function getGenderList()
    {
        return [0=>'女',1=>'男'];
    }


    public function getGenderTextAttr($value, $data)
    {
        $value = $value ?: ($data['gender'] ?? '');
        $list = $this->getGenderList();
        return $list[$value] ?? '';
    }
}
